<?php 
require $this->website['path']['action'].'/admin/isadmin.php';

$json = array('status'=>'error','msg'=>'error','data'=>'');
$id = fn_post('id');
$uname = fn_post('uname');

$pwd = fn_post('pwd');
$visible = fn_post('visible');
$authority = fn_post('authority');
$authoritylist = fn_post('authoritylist');

$user = $this->website['class']['db']
             ->table('user_admin')
             ->where('id=?',$id)
             ->one();
$bool = $user['uname']??false;

if(!$bool){
  $json['msg'] = 'user';
  $json['data']= '未找到此用户';
}elseif($user['uname']!=$uname && $this->website['class']['db']->table('user_admin')->where('uname=?',$uname)->count()){
  $json['msg'] = 'uname';
  $json['data']= '用户名已存在';
}else{
    $field=[];
    $value=[];
    if($uname && strlen($uname)>2 && strlen($uname)<21 && $user['uname'] !=$uname && !$this->website['class']['db']->table('user_admin')->where('uname=?',$uname)->count()){$field[] = 'uname';$value[] = $uname;}
    if($pwd && !password_verify($user['id'].$pwd,$user['pwd'])){$field[] = 'pwd';$value[] = password_hash($user['id'].$pwd,PASSWORD_DEFAULT);}
    if($user['authority'] !=$authority){$field[] = 'authority';$value[] = $authority;}
    if($user['authoritylist'] !=$authoritylist){$field[] = 'authoritylist';$value[] = $authoritylist;}

    if(count($field)){
      $this->website['class']['db']
         ->table('user_admin')
         ->field($field)
         ->value($value)
         ->where('id=?',$id)
         ->update();
      $json['status'] = 'ok';
      $json['msg'] = '修改成功';
      $json['data']= 'ok';
    }else{
      $json['msg'] = 'update';
      $json['data']= '账户未改变!'.$authority;
    }
}




echo json_encode($json);